package com.itshen.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/mail")
public class MailController {

    @Autowired
    private JavaMailSender mailSender;

    @RequestMapping("/send")
    public void sendMail() {

        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("shenzhaoxiang@ctsig.com");
        message.setTo("shenzhaoxiang@ctsig.com");
        message.setSubject("it is a test for spring boot");
        message.setText("你好，我正在测试发送邮件。");

        try {
            mailSender.send(message);
            log.info("测试邮件已发送。");
        } catch (Exception e) {
            log.error("发送邮件时发生异常了！", e);
        }
    }
}